package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.PerformanceInterview;
import com.amsp.oa.oademo.service.PerformanceInterviewService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/performance-interview")
@Api(tags = "绩效面谈记录管理")
@CrossOrigin
public class PerformanceInterviewController {

    @Autowired
    private PerformanceInterviewService interviewService;

    @PostMapping("/save")
    @ApiOperation("保存绩效面谈记录")
    public PerformanceInterview save(@RequestBody PerformanceInterview interview) {
        LocalDateTime now = LocalDateTime.now();
        if (interview.getId() == null) {
            interview.setCreateTime(now);
        }
        interview.setUpdateTime(now);
        interviewService.saveOrUpdate(interview);
        return interview;
    }

    @GetMapping("/list")
    @ApiOperation("获取绩效面谈记录列表")
    public IPage<PerformanceInterview> list(
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String appraiser,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String department,
            @RequestParam(required = false) String interviewType,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime) {
        return interviewService.getPage(current, size, appraiser, employeeId, department, interviewType, startTime,
                endTime);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取绩效面谈记录详情")
    public PerformanceInterview getById(@PathVariable Long id) {
        return interviewService.getById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除绩效面谈记录")
    public boolean delete(@PathVariable Long id) {
        return interviewService.removeById(id);
    }
}